﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Simhopp.GUI;
using Simhopp.Model;

namespace Simhopp.Presenter
{
    class PresenterCoordinator
    {
        public InterfaceCoordinatorView _view { get; set; }
        public InterfaceCompetitionListModel _model { get; set; }

        public PresenterCoordinator(InterfaceCoordinatorView view, InterfaceCompetitionListModel model)
        {
            this._view = view;
            this._model = model;
            this._view.EventCreate += _view_EventCreate;
            this._view.EventGetCompetitionList += _view_EventGetCompetitionList;
            this._view.EventManageEvent += _view_EventManageEvent;
            this._view.EventStartEvent += _view_EventStartEvent;
            this._view.EventEditJudges += _view_EventEditJudges;
            this._view.EventEditDiver += _view_EventEditDiver;
            this._view.EventInitializeCompetitionList += _view_EventInitializeCompetitionList;
            this._view.EventCompetitionList += _view_EventCompetitionList;
        }

        List<Competition> _view_EventCompetitionList()
        {
            return this._model.competitionList;
        }

        void _view_EventStartEvent(Competition competition)
        {
            if (competition.MakeSureCompetitionIsReadyToStart())
            {
                frmOngoingCompetition fOngoingCompetition = new frmOngoingCompetition(competition);
                fOngoingCompetition.ShowDialog();
            }

        }

        CompetitionList _view_EventInitializeCompetitionList()
        {
            return this._model.InitializeCompetitionList();
        }

        void _view_EventEditDiver(Competition competition)
        {
            frmEditDivers formEditDivers = new frmEditDivers(competition);
            formEditDivers.ShowDialog();
        }

        void _view_EventEditJudges(Competition competition)
        {
            frmEditJudges editJudges = new frmEditJudges(competition);
            
            editJudges.ShowDialog();
        }

        void _view_EventManageEvent(CompetitionList competitionList, Competition competition)
        {
            frmManageCompetition ManageCompetition = new frmManageCompetition();
            //Fixa
            PresenterManageCompetition pManageCompetition = new PresenterManageCompetition(ManageCompetition,competitionList,competition);
            ManageCompetition.ShowDialog();
        }

        CompetitionList _view_EventGetCompetitionList()
        {
            return this._model.GetCompetitionList();
        }

        void _view_EventCreate(CompetitionList competitionList)
        {
            frmAddCompetition AddCompetition = new frmAddCompetition();
            PresenterAddCompetition pAddCompetition = new PresenterAddCompetition(AddCompetition, competitionList);
            AddCompetition.ShowDialog();
        }
        
    }
}
